package remato.domain.server.ejb;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.GenerationType.AUTO;
import static javax.persistence.InheritanceType.TABLE_PER_CLASS;

import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import remato.common.domain.helpers.ProjectParentable;
import remato.domain.common.Category;
import remato.domain.common.CategoryParentable;
import remato.domain.common.Project;
import remato.domain.common.impl.ProjectImpl;

@Entity
@Inheritance(strategy = TABLE_PER_CLASS)
public class ProjectEjb extends ProjectImpl implements Project, CategoryParentable, ProjectParentable {
	
	@Override
	@Id
	@GeneratedValue(strategy=AUTO)
	public Long getDbId() {
		return super.getDbId();
	}
	
	@Override
	public String getDescription() {
		return super.getDescription();
	}

	@Override
	@Lob
	public String getName() {
		return super.getName();
	}

	@Override
	@OneToMany(mappedBy="projectParent", targetEntity=ProjectEjb.class, cascade={ALL})
	public Set<Project> getProjectChildren() {
		return super.getProjectChildren();
	}
	
	@Override
	@OneToMany(mappedBy="projectParentField", targetEntity=CategoryEjb.class, cascade={ALL})
	public Set<Category> getCategoryChildren() {
		return super.getCategoryChildren();
	}
	
	@Override
	@ManyToOne(targetEntity=ProjectEjb.class)
	public Project getProjectParent() {
		return super.getProjectParent();
	}

	/**
	 * Needed to trigger CGLib proxy (ie. if other CGLib-proxies is used as 
	 * parameter.)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}

	
}
